<template>
  <div class="admin-panel">
    <div class="admin-panel-header">
      <div class="header-content">
        <div class="header-left">
          <div class="page-header">
            <div class="main-title">项目管理中心</div>
            <span class="title-separator">/</span>
            <div class="project-name">{{ projectStore.getProjectInfo().name || '-' }}</div>
          </div>
          <div class="breadcrumb">
            <span @click="handleGoBack" class="breadcrumb-item">
              <IconHome class="w-12px h-12px" />
              首页
            </span>
            <span class="breadcrumb-separator">></span>
          </div>
        </div>
        <div class="header-right">
          <div class="user-info">
            <div class="user-avatar">
              <img src="@/assets/user.webp" alt="用户头像">
              <div class="user-status online"></div>
            </div>
            <div class="user-details">
              <div class="user-name">{{ projectStore.getUsefProjectInfo().nickname || '-' }}</div>
              <div class="user-role">{{ projectStore.getUsefProjectInfo().role_name || '-' }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="admin-panel-content">
      <Layout :module="'admin-panel'"></Layout>
    </div>
  </div>
</template>

<script setup lang="ts">
import Layout from '@/common/components/layout/admin-panel-layout/index.vue';
import router from '@/router';
import { useProjectStore } from '@/store/modules/project';
import { onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { useUserStore } from "@/store/modules/user.ts";

const route = useRoute();
const projectStore = useProjectStore();
const userStore = useUserStore();

const handleGoBack = () => {
  router.push(`/project/${Number(route.params.id)}`);
};

onMounted(async () => {
  await projectStore.setProjectInfo(Number(route.params.id));
  await projectStore.setUserProjectInfo(userStore.getUserInfo().id, Number(route.params.id));
});
</script>

<style lang="less" scoped>
.admin-panel {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);

  .admin-panel-header {
    border-bottom: 1px solid var(--border-light);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    z-index: 10;
    background: var(--header-bg);

    .header-content {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 24px;
      width: 100%;

      .header-left {
        display: flex;
        flex-direction: column;
        gap: 4px;

        .page-header {
          display: flex;
          align-items: center;
          gap: 12px;
          margin-bottom: 8px;

          .main-title {
            font-size: 18px;
            font-weight: 700;
            color: var(--text-primary);
            line-height: 1.2;
          }

          .title-separator {
            color: var(--border-color);
            font-weight: 300;
            font-size: 20px;
          }

          .project-name {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-secondary);
            line-height: 1.2;
          }
        }

        .breadcrumb {
          display: flex;
          align-items: center;
          gap: 8px;
          font-size: 12px;
          color: var(--text-secondary);

          .breadcrumb-item {
            display: flex;
            align-items: center;
            gap: 4px;
            transition: color 0.2s ease;
            cursor: pointer;

            i,
            svg {
              /* 让图标继承父元素颜色 */
              color: currentColor;
              fill: currentColor;
            }

            &:hover {
              color: var(--primary-color);
            }

            &.active {
              color: var(--text-secondary);
              font-weight: 400;
              cursor: default;

              &:hover {
                color: var(--text-secondary);
              }
            }
          }

          .breadcrumb-separator {
            color: var(--border-color);
            font-weight: 300;
          }
        }
      }

      .header-right {
        .user-info {
          display: flex;
          align-items: center;
          gap: 12px;
          padding: 8px 16px;
          background: var(--bg-secondary);
          border-radius: 8px;
          border: 1px solid var(--border-light);
          transition: all 0.2s ease;

          &:hover {
            background: var(--bg-hover);
            border-color: var(--border-color);
          }

          .user-avatar {
            position: relative;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            overflow: hidden;
            border: 2px solid var(--border-light);
            flex-shrink: 0;

            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
            }

            .user-status {
              position: absolute;
              bottom: 2px;
              right: 2px;
              width: 10px;
              height: 10px;
              border-radius: 50%;
              border: 2px solid var(--border-color);

              &.online {
                background: var(--success-color);
              }

              &.offline {
                background: var(--text-secondary);
              }

              &.away {
                background: var(--warning-color);
              }
            }
          }

          .user-details {
            display: flex;
            flex-direction: column;
            gap: 2px;

            .user-name {
              font-size: 14px;
              font-weight: 600;
              color: var(--text-primary);
              line-height: 1.2;
            }

            .user-role {
              font-size: 12px;
              color: var(--text-secondary);
              line-height: 1.2;
            }
          }
        }
      }
    }
  }

  .admin-panel-content {
    flex: 1;
  }

  // 响应式设计
  @media (max-width: 768px) {
    .admin-panel-header {
      .header-content {
        padding: 12px 16px;
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;

        .header-left {
          width: 100%;

          .page-header {
            .main-title {
              font-size: 20px;
            }

            .project-name {
              font-size: 18px;
            }

            .title-separator {
              font-size: 18px;
            }
          }

          .breadcrumb {
            font-size: 11px;
          }
        }

        .header-right {
          width: 100%;

          .user-info {
            width: 100%;
            justify-content: flex-start;
          }
        }
      }
    }
  }

  @media (max-width: 480px) {
    .admin-panel-header {
      .header-content {
        padding: 10px 12px;

        .header-left {
          .page-header {
            .main-title {
              font-size: 18px;
            }

            .project-name {
              font-size: 16px;
            }

            .title-separator {
              font-size: 16px;
            }
          }

          .breadcrumb {
            font-size: 10px;
          }
        }

        .header-right {
          .user-info {
            padding: 6px 12px;

            .user-avatar {
              width: 32px;
              height: 32px;
            }

            .user-details {
              .user-name {
                font-size: 13px;
              }

              .user-role {
                font-size: 11px;
              }
            }
          }
        }
      }
    }
  }
}
</style>